function getUrlParam(sUrl, sKey) {
    var reg = /\w+=\w+/gim;
    var resArr = sUrl.match(reg);
    var obj = {};
    for (let i = 0; i < resArr.length; i++) {
        var valArr = resArr[i].split('=');
        if (!obj[valArr[0]]) {
            obj[valArr[0]] = [];
            obj[valArr[0]].push(valArr[1]);
        } else {
            obj[valArr[0]].push(valArr[1]);
        }
    }

    if (!sKey) {
        var arr = [];
        for (key in obj) {
            arr = arr.concat(obj[key]);
        }
        return arr;
    }
    for (key in obj) {
        if (key == sKey) {
            if (obj[key].length <= 1) {
                return obj[key].toString();
            } else {
                return obj[key];
            }
        }
    }
}

var res = (function() {
    var a = getUrlParam('http://www.nowcoder.com?key=1&key=2&key=3&key=4&test1=4#hehe', 'key');
    return a;
})();
console.log(res);